﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Player.Admin
{
    public partial class live : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //刷新表
                rpt_liveSX();
                //修改信息展示
                if (Request.QueryString["upid"]!=null)
                {
                    this.pl_add.Visible = false;
                    this.Pl_update.Visible = true;
                    int upid = Convert.ToInt32(Request.QueryString["upid"]);
                    List<Live> ls = BLL.LiveManage.SeleIdLive(upid);
                    this.lbl_pl2lvid.Text = ls[0].Lv_Id.ToString();
                    this.txt_pl2gmid.Text = ls[0].Lv_GmId.ToString();
                    this.txt_pl2gtid.Text = ls[0].Lv_GtId.ToString();
                    this.txt_pl2lvname.Text = ls[0].Lv_Tv.ToString();
                    this.txt_pl2gmname.Text = ls[0].Lv_Title.ToString();
                }
                if (Request.QueryString["deid"] != null)
                {
                    this.pl_delete.Visible = true;
                }
            }
        }

        //刷新表
        private void rpt_liveSX()
        {
            this.rpt_live.DataSource = BLL.LiveManage.SeleAllLive();
            this.rpt_live.DataBind();
        }

        //添加信息框显示
        protected void btn_add_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
            this.pl_add.Visible = true;
        }

        //保存添加信息
        protected void btn_plbc_Click(object sender, EventArgs e)
        {
            //获取输入内容保存至Live中
            Live lv = new Live();
            lv.Lv_GmId = Convert.ToInt32(this.txt_plgmId.Text.Trim());
            lv.Lv_GtId = Convert.ToInt32(this.txt_plgtid.Text.Trim());
            lv.Lv_Title = this.txt_plgmname.Text.Trim();
            lv.Lv_Tv = this.txt_pllvname.Text.Trim();
            //新增
            bool bl = BLL.LiveManage.AddLive(lv);
            if (bl)
            {
                this.lbl_plbcts.Text = "保存成功";
                //刷新表
                rpt_liveSX();
            }
            else
            {
                this.lbl_plbcts.Text = "保存失败";
            }

        }

        //添加信息框隐藏
        protected void btn_plgb_Click(object sender, EventArgs e)
        {
            this.pl_add.Visible = false;
        }

        //保存修改信息
        protected void btn_pl2bc_Click(object sender, EventArgs e)
        {
            //获取内容保存至Live中
            Live lv = new Live();
            lv.Lv_Id = Convert.ToInt32(this.lbl_pl2lvid.Text.Trim());
            lv.Lv_GmId = Convert.ToInt32(this.txt_pl2gmid.Text.Trim());
            lv.Lv_GtId = Convert.ToInt32(this.txt_pl2gtid.Text.Trim());
            lv.Lv_Title = this.txt_pl2gmname.Text.Trim();
            lv.Lv_Tv = this.txt_pl2lvname.Text.Trim();
            //修改
            bool bl = BLL.LiveManage.UpdaLive(lv);
            if (bl)
            {
                this.lbl_pl2bcts.Text = "保存成功";
                //刷新表
                rpt_liveSX();
            }
            else
            {
                this.lbl_pl2bcts.Text = "保存失败";
            }
        }

        //修改信息框隐藏
        protected void btn_pl2gb_Click(object sender, EventArgs e)
        {
            this.Pl_update.Visible = false;
        }

        //类型名称替换类型id
        public string GtIdisName(int id)
        {
            List<GmType> ls = BLL.GmTypeManage.SeleIdGmType(Convert.ToInt32(id));
            return ls[0].Gt_Name;
        }

        //确定删除
        protected void btn_delequedin_Click(object sender, EventArgs e)
        {
            int lvid = Convert.ToInt32(Request.QueryString["deid"]);
            bool bl = BLL.LiveManage.DeleLive(lvid);
            if (bl)
            {
                this.pl_delete.Visible = false;
                //刷新表
                rpt_liveSX();
            }
        }

        //取消删除
        protected void btn_delequxiao_Click(object sender, EventArgs e)
        {
            this.pl_delete.Visible = false;
        }

        //刷新按钮
        protected void imgbtnsx_Click(object sender, ImageClickEventArgs e)
        {
            rpt_liveSX();
        }

        //查询
        protected void imgbtn_Click(object sender, ImageClickEventArgs e)
        {
            //获取输入内容
            string name = this.txt_game.Text.Trim();
            //判断是否输入
            if (name=="")
            {
                this.lbl_ChaXunTiShi.Text = "请输入查询内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            //查询
            List<Live> ls = BLL.LiveManage.SeleGameLive(name);
            if (ls.Count==0)
            {
                this.lbl_ChaXunTiShi.Text = "未找到相关内容";
                this.img_weizhaodao.Visible = true;
                return;
            }
            this.lbl_ChaXunTiShi.Text = "";
            this.img_weizhaodao.Visible = false;
            this.rpt_live.DataSource = ls;
            this.rpt_live.DataBind();
        }

    }
}